import request from '@/utils/request';
import { HTTP_METHOD } from '@/utils/http';

const BASE_URL = '/auth';

/**
 * 用户登录
 * @param {*} email
 * @param {*} password
 * @param {*} remember_me
 * @return {*}
 */
 export function login(data) {
  return request({
    url: `${BASE_URL}/login/pwd`,
    method: HTTP_METHOD.POST,
    data
  });
}

/**
 * 用户登录
 * @param {*} mobile
 * @param {*} code
 * @param {*} remember_me
 * @return {*}
 */
export function postLogin(data) {
  return request({
    url: `${BASE_URL}/login/pwd`,
    method: HTTP_METHOD.POST,
    data
  });
}

/**
 * @export 邮箱验证码发送
 * @param {*} email
 * @param {*} first_name
 * @param {*} last_name
 * @return {*}
 */
 export function sendEmailCode(data) {
  return request({
    url: `${BASE_URL}/email_code`,
    method: HTTP_METHOD.POST,
    data
  });
}

/**
 * @export 手机验证码发送
 * @param {*} mobile
 * @param {*} first_name
 * @param {*} last_name
 * @return {*}
 */
 export function sendMobileCode(data) {
  return request({
    url: `${BASE_URL}/mobile_code`,
    method: HTTP_METHOD.POST,
    data
  });
}

/**
 * @export 邮箱验证码校验
 * @param {*} email
 * @param {*} code
 * @return {*}
 */
export function emailVerifyCode(data) {
  return request({
    url: `${BASE_URL}/email_verify_code`,
    method: HTTP_METHOD.POST,
    data
  });
}

/**
 * @export 手机号验证码校验
 * @param {*} email
 * @param {*} code
 * @return {*}
 */
 export function mobileVerifyCode(data) {
  return request({
    url: `${BASE_URL}/mobile_verify_code`,
    method: HTTP_METHOD.POST,
    data
  });
}

export function getSmsCaptcha(parameter) {
  return request({
    url: '/message/sms',
    method: 'post',
    data: parameter
  });
}

/**
 * 获取用户信息
 * @param {`*`} token
 */
export function getInfo() {
  return request({
    url: `${BASE_URL}/info`,
    method: HTTP_METHOD.GET
  });
}

/**
 * @export 退出登录
 * @return {*}
 */
export function logout() {
  return request({
    url: `${BASE_URL}/logout`,
    method: HTTP_METHOD.POST
  });
}

/**
 * @export 重置用户密码
 * @param {*} data
 */
export function resetPassword(data) {
  return request({
    url: `${BASE_URL}/reset_password`,
    method: HTTP_METHOD.POST,
    data
  });
}

/**
 * @export 修改用户密码
 * @param {*} data
 */
 export function modifyPassword(data) {
  return request({
    url: `${BASE_URL}/login/pwd`,
    method: HTTP_METHOD.PUT,
    data
  });
}

/**
 * @export 获取用户信息
 * @return {*}
 */
export function getUserInfo() {
  return request({
    url: `${BASE_URL}/personal_detail`,
    method: HTTP_METHOD.GET
  });
}

/**
 * @export 修改用户个人信息
 * @param {*} data
 * @return {*}
 */
export function modifyUserInfo(data) {
  return request({
    url: `${BASE_URL}/personal_detail`,
    method: HTTP_METHOD.PUT,
    data
  });
}

/**
 * @export 认证用户邮箱
 * @param {*} email
 * @param {*} code
 * @return {*}
 */
 export function authEmail(data) {
  return request({
    url: `${BASE_URL}/email_authorization_code`,
    method: HTTP_METHOD.POST,
    data
  });
}

/**
 * @export 绑定用户邮箱
 * @param {*} email
 * @param {*} code
 * @return {*}
 */
 export function bindEmail(data) {
  return request({
    url: `${BASE_URL}/bind_email`,
    method: HTTP_METHOD.POST,
    data
  });
}

/**
 * @export 改变银行授权状态
 * @return {*}
 */
 export function changeBackStatus() {
  return request({
    url: `${BASE_URL}/personal_backcard_status`,
    method: HTTP_METHOD.PUT
  });
}
